﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace LightGameLibs
{
    /// <summary>
    /// 继承这个类来实现使用Inspector来调用SysEventMgr中的方法
    /// </summary>
    /// <typeparam name="TEnum"></typeparam>
    public class SysEventMB<TEnum> : MonoBehaviour
    {
        private Dictionary<string, int> m_name2IndexDict = new Dictionary<string, int>();

        public void Invoke(string enumName)
        {
            int index = -1;
            if (m_name2IndexDict.TryGetValue(enumName, out index))
            {
                SysEventMgr.Invoke(index);
                return;
            }

            object parsed = Enum.Parse(typeof(TEnum), enumName);
            if (null == parsed)
            {
                DebugMgr.LogError(DebugTag.EVENT, "Enum Parse Error");
                return;
            }

            int result = (int)parsed;

            m_name2IndexDict.Add(enumName, result);
            SysEventMgr.Invoke(result);
        }
    }
}
